from os.path import join, dirname
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette, QBrush, QPixmap
from PyQt5.QtWidgets import QWidget, QApplication

img_file = join(dirname(__file__), "res", "test.jpg")
app = QApplication([])
w = QWidget()
w.setWindowTitle("窗口背景设置示例1")
palette = QPalette()
palette.setBrush(w.backgroundRole(), 
                 QBrush(
                    QPixmap(img_file).scaled(
                        w.size(), 
                        Qt.IgnoreAspectRatio, 
                        Qt.SmoothTransformation)
                    )
                 )
w.setPalette(palette)
w.show()
app.exec_()
